package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.entity.WmNews;
import com.heima.media.service.IWmNewsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author Wq
 * @since 2022-10-09
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController {

    @Autowired
    private IWmNewsService wmNewsService;

    /**
     * 自媒体文章列表查询
     *
     * @param dto dto
     * @return {@code ResponseResult}
     */
    @PostMapping("/list")
    public ResponseResult pageByCondition(@RequestBody WmNewsPageDto dto) {
        return wmNewsService.pageByCondition(dto);
    }

    /**
     * 根据id查询文章回显
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable Integer id) {
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    /**
     * 自媒体文章提交与修改
     *
     * @param dto dto
     * @return {@code ResponseResult}
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }


    /**
     * 文章上下架
     *
     * @param dto dto
     * @return {@code ResponseResult}
     */
    @PutMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }


}
